﻿using IntelligentAgriculture.Contracts.Interface.EarTagService;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.EarTageCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.EarTageManageCommandJamdler
{
    public class EarTageUpdateCommandHandler : IRequestHandler<EarTageUpdateCommand, Results<int>>
    {
        private readonly IEarTageService _iearTageService;

        public EarTageUpdateCommandHandler(IEarTageService _iearTageServices)
        {
            _iearTageService = _iearTageServices;
        }
        /// <summary>
        /// 修改功能
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<int>> Handle(EarTageUpdateCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var entity = new Eartag()
                {
                    Id=request.id,
                    EarTagBirthStatus = request.EarTagBirthStatus,
                    EarTagUseStatus = request.EarTagUseStatus,
                    BeforNumber = request.BeforNumber,
                    AfterNumber = request.AfterNumber,
                    EarTagBreeds = request.EarTagBreeds,
                    EarTagNumber = request.EarTagNumber,
                    EarTagInHouseDate = DateTime.Now,
                    Isdel = false
                };

                var list = await _iearTageService.UpateEartag(entity);
                return Results<int>.DataResult(list);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
